package com.hmall.api.config;

import com.hmall.common.utils.UserContext;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfig {
    @Bean
    public Logger.Level FeignLoggerLevel(){
        return Logger.Level.FULL;
    }
    public RequestInterceptor userInfoRequestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate template) {
                //获取登录用户
                Long userId = UserContext.getUser();
                if(userId==null){
                    return;
                }
                template.header("user-info",userId.toString());
            }
        };
    }
}
